package org.examSys.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.examSys.Dao.BookDao;
import org.examSys.Dao.GradeDao;
import org.examSys.Dao.ImpI.BookDaoImpI;
import org.examSys.Dao.ImpI.GradeDaoImpI;
import org.examSys.entity.Book;
import org.examSys.entity.Grade;
@WebServlet(urlPatterns="/index.shtml")
public class indexservlet extends HttpServlet {
		@Override
		protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			GradeDao  gradeDao=new GradeDaoImpI();
			List<Grade> gradelisst=gradeDao.getAll();
			req.setAttribute("gradelisst", gradelisst);
			
			String name=req.getParameter("name");
			String gradeid=req.getParameter("gradeid");
			Book book=new Book();
			book.setBookName(name);
			if(gradeid!=null) {
				book.setGrade_id(Integer.parseInt(gradeid));
			}
			BookDao bookDao=new BookDaoImpI();
			List<Book> booklist=bookDao.select(book);
			req.setAttribute("booklist", booklist);
			
			req.getRequestDispatcher("/index.jsp").forward(req, resp);
		}
}
